<?php

class Default_Form_OghTinRao extends Zend_Form {
	
	const TITLE_LABEL         		= 'Tiêu đề';
	const ADDRESS_LABEL          	= 'Địa chỉ';
	const SEX_LABEL          		= 'Giới tính';
	const CITY_LABEL          		= 'Thành phố';
	const DISTRICT_LABEL          	= 'Quận huyện';
	const IMAGE_LABEL            	= 'Hình ảnh';
	const DESCRIPTION_LABEL         = 'Mô tả';
	const CONTACTNAME_LABEL         = 'Tên người liên hệ';
	const TEL_LABEL              	= 'Điện thoại';
	const KINDOFROOM_LABEL          = 'Loại phòng';
	const NUMMEMBER_LABEL           = 'Số người ở';
	const DIENTICH_LABEL           	= 'Diện tích (m<sup>2</sup>)';
	const GIAPHONG_LABEL         	= 'Giá ở ghép';
	const LOAITIN_LABEL          	= 'Loại tin';
	
	const ENCODING               	= 'UTF-8';
	const TITLE_MIN_LENGTH    		= 20;
	const TITLE_MAX_LENGTH    		= 200;
	const DESCRIPTION_MIN_LENGTH    = 100;
	const DESCRIPTION_MAX_LENGTH    = 500;
	const CONTACTNAME_MIN_LENGTH    = 0;
	const CONTACTNAME_MAX_LENGTH    = 50;
	
    public function init() {
        $this->setName('frmOghTinRao');
		$id = new Zend_Form_Element_Hidden('id');
		$id->addFilter('Int');
		
		// Title
		$title = self::addTitle();
		
		// Address
		$address = self::addAddress();
		
		//Sex
		$sex = self::addSex();
		
        // Avatar	
        $uploadImage = self::addAvatar();
		
        // Kind of room	
        $kindOfRoom = self::addKindOfRoom();
		
        // Number member
        $numMember = self::addNumMember();
		
        // Diện tích
        $acreage = self::addAcreage();
		
        // Thành phố
        $city = self::addCity();
		
        // Quận huyện
        $district = self::addDistrict();
		
        // Giá phòng
        $priceRoom = self::addPriceRoom();
		
        // Kind of news
        $kindOfNews = self::addKindOfNews();
		
		// Description
		$description = self::addDescription();
		
        // Contact name
        $contactName = self::addContactName();
		
		// Telephone
		$tel = self::addTel();
        
		//Button
       	$submit = new Zend_Form_Element_Submit('submit');
        $submit ->setAttrib('id', 'submitbutton')
        		->setAttrib("class", "btn btn-large btn-primary ")
        		->removeDecorator('DtDdWrapper');
        $reset = new Zend_Form_Element_Submit('reset');
        $reset	->setAttrib('id', 'resetbutton')
        		->setAttrib("class", "btn btn-large")
        		->removeDecorator('DtDdWrapper');
		
		$this->addElements(array($id, $title, $uploadImage, $address, $sex, $city, $district, $kindOfRoom, $numMember, $acreage, $priceRoom, $kindOfNews, $description, $contactName, $tel, $submit, $reset));
		
		$this->addDisplayGroup(array('submit', 'reset'), 'buttons');
        $dg = $this->getDisplayGroup('buttons');
        $dg->removeDecorator('Fieldset');
        $dg->removeDecorator('HtmlTag');
    }

	/*
	 * Add title element
	 */
	protected  function addTitle() {
		$notEmptyTitle = new Zend_Validate_NotEmpty();
        $title = new Zend_Form_Element_Text('tieu_de');
        $title	->setLabel(self::TITLE_LABEL)
        		->addFilter('StripTags')
        		->addFilter('StringTrim')
        		->setRequired(true)
        		->addValidator($notEmptyTitle, true);
        
        return $title;
	}
	
	/*
	 * Add address element
	 */
	protected  function addAddress() {
		$notEmptyAddress = new Zend_Validate_NotEmpty();
		$address = new Zend_Form_Element_Text('dia_chi');
		$address->setLabel(self::ADDRESS_LABEL)
         		->addFilter('StripTags')
         		->addFilter('StringTrim')
         		->setRequired(true)
         		->addValidator($notEmptyAddress, true);
        
        return $address;
	}

	/*
	 * Add sex element
	 */
	protected function addSex() {
		 $sex = new Zend_Form_Element_Radio('gioi_tinh');
         $sex	->setLabel(self::SEX_LABEL)
         		->setSeparator('')
         		->setValue('1')
         		->addMultiOptions(array(
        					false => 'Nam',
        					true => 'Nữ'));
        return $sex;
	}
	
	/*
	 * Add city element
	 */
	protected function addCity() {
		$notEmptyCity = new Zend_Validate_NotEmpty();
		$city = new Zend_Form_Element_Select('thanh_pho');
		$city ->setLabel(self::CITY_LABEL)
					->setRequired(true)
					->setRegisterInArrayValidator(false)
					->addValidator($notEmptyCity, true);
		
		return $city;
	}
	
	/*
	 * Add kind of news element
	 */
	protected function addDistrict() {
		$notEmptyDistrict = new Zend_Validate_NotEmpty();
		$district = new Zend_Form_Element_Select('quan_huyen');
		$district ->setLabel(self::DISTRICT_LABEL)
					->setRequired(true)
					->setRegisterInArrayValidator(false)
					->addValidator($notEmptyDistrict, true)
					->addMultiOption("", "-- Quận huyện --");;
		
		return $district;
	}

	/*
	 * Add avatar
	 */
	protected function addAvatar() {
		//avatar
       	$uploadImage = new Zendhlt_Form_Element_Upload('hinh_anh');
       	$uploadImage->setLabel(self::IMAGE_LABEL);
        return $uploadImage;
	}
	
	/*
	 * Add kind of room element
	 */
	protected function addKindOfRoom() {
		$notEmptyKindOfRoom = new Zend_Validate_NotEmpty();
		$kindOfRoom = new Zend_Form_Element_Select('loai_phong');
		$kindOfRoom ->setLabel(self::KINDOFROOM_LABEL)
					->setRequired(true)
					->setRegisterInArrayValidator(false)
					->addValidator($notEmptyKindOfRoom, true);
		
		return $kindOfRoom;
	}
	
	/*
	 * Add số người ở
	 */
	protected  function addNumMember() {
		$notEmptyNumMember = new Zend_Validate_NotEmpty();
		$numMember = new Zend_Form_Element_Text('so_nguoi_o');
		$numMember->setLabel(self::NUMMEMBER_LABEL)
         		  ->addFilter('StripTags')
         		  ->addFilter('StringTrim')
         		  ->setRequired(true)
         		  ->addValidator($notEmptyNumMember, true);
        
        return $numMember;
	}
	
	/*
	 * Add diện tích
	 */
	protected  function addAcreage() {
		$notEmptyAcreage = new Zend_Validate_NotEmpty();
		$acreage = new Zend_Form_Element_Text('dien_tich_phong');
		$acreage->setLabel(self::DIENTICH_LABEL)
				->addDecorator('Label', array('tag' => 'dt', 'escape' => false))
         		->addFilter('StripTags')
         		->addFilter('StringTrim')
         		->setValue('0')
         		->setRequired(true)
         		->addValidator($notEmptyAcreage, true);
        
        return $acreage;
	}

	/*
	 * Add price room element
	 */
	protected function addPriceRoom() {
		//Not empty
        $priceNotEmpty = new Zend_Validate_NotEmpty();
        //Float 
        $priceFloat = new Zend_Validate_Float('en');
		$price = new Zend_Form_Element_Text('gia_o_ghep');
        $price	->setLabel(self::GIAPHONG_LABEL)
        		->addDecorator('Description', array('escape' => false))
        		->setDescription('Nhập số theo định dạng: 1234.500. Đơn vị là VNĐ<br/>Ví Dụ: 2,800,500 đồng thì nhập 2800.5 (2,800,000 thì nhập 2800)')
        		->setValue('0')
        		->addFilter('StripTags')
        		->addFilter('StringTrim')
        		->addValidator($priceNotEmpty, true)
        		->addValidator($priceFloat);
        		
        return $price;
	}
	
	/*
	 * Add kind of news element
	 */
	protected function addKindOfNews() {
		$notEmptyKindOfNews = new Zend_Validate_NotEmpty();
		$kindOfRoom = new Zend_Form_Element_Select('loai_tin');
		$kindOfRoom ->setLabel(self::LOAITIN_LABEL)
					->setRequired(true)
					->setRegisterInArrayValidator(false)
					->addValidator($notEmptyKindOfNews, true);
		
		return $kindOfRoom;
	}

	/*
	 * Add description element
	 */
	protected function addDescription() {
        $description = new Zend_Form_Element_Textarea('mo_ta');
        $description->setLabel(self::DESCRIPTION_LABEL)
        			->addFilter('StripTags')
        			->addFilter('StringTrim')
        			->setRequired(true);
        
        return $description;
	}

	/*
	 * Add contact name element
	 */
	protected function addContactName() {
		$notEmptyContactName = new Zend_Validate_NotEmpty();
        //Length validate
        $contactnameLength = new Zend_Validate_StringLength(self::CONTACTNAME_MIN_LENGTH, self::CONTACTNAME_MAX_LENGTH, self::ENCODING);
        $contactname = new Zend_Form_Element_Text('nguoi_lien_he');
        $contactname->setLabel(self::CONTACTNAME_LABEL)
        			->addFilter('StripTags')
        			->addFilter('StringTrim')
        			->setRequired(true)
        			->addValidator($contactnameLength)
        			->addValidator($notEmptyContactName, true);
        			
        return $contactname;
	}

	/*
	 * Add tel
	 */
	protected function addTel() {
		$notEmptyTelephone = new Zend_Validate_NotEmpty();
        $telephone = new Zend_Form_Element_Text('so_dien_thoai');
        $telValidator = new Zendhlt_Validate_Phone();
        $telephone	->setLabel(self::TEL_LABEL)
        			->addDecorator('Description', array('escape' => false) )
        			->setDescription('Nhập theo định dạng: (xxx)xxx-xxxx nếu 10 số hay (xxxx)xxx-xxxx nếu 11 số.<br/> Ví dụ: (098)999-9999 hay (0167)999-9999')
        			->addFilter('StripTags')
        			->addFilter('StringTrim')
        			->setRequired(true)
        			->addValidator($notEmptyTelephone, true);
        
        return $telephone;
	}
}